31 Lecture

CS402

Midterm & Final Term Short Notes

CFG terminologies

Some of the key terminologies related to Context-Free Grammar (CFG) include non-terminal symbols, terminal symbols, production rules, start symbol, leftmost derivation, rightmost derivation, parse tree, ambiguity, and Chomsky normal form. These


Important Mcq's
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. Which of the following symbols can be rewritten by production rules in a Context-Free Grammar? A. Non-terminal symbols only B. Terminal symbols only C. Both non-terminal and terminal symbols D. None of the above Answer: A What is the start symbol in a Context-Free Grammar? A. The first non-terminal symbol in the grammar B. The last non-terminal symbol in the grammar C. A special non-terminal symbol that represents the entire language generated by the grammar D. A special terminal symbol that represents the empty string Answer: C Which of the following is not a part of a production rule in a Context-Free Grammar? A. Non-terminal symbol on the left-hand side B. Terminal symbol on the right-hand side C. Non-terminal symbol on the right-hand side D. None of the above Answer: B What is a leftmost derivation in a Context-Free Grammar? A. A derivation in which the leftmost non-terminal symbol is always replaced in each step B. A derivation in which the leftmost terminal symbol is always replaced in each step C. A derivation in which the rightmost non-terminal symbol is always replaced in each step D. A derivation in which the rightmost terminal symbol is always replaced in each step Answer: A What is a parse tree in the context of Context-Free Grammar? A. A tree structure that represents the syntactic structure of a string derived from the grammar B. A tree structure that represents the semantic structure of a string derived from the grammar C. A tree structure that represents the alphabet of the grammar D. None of the above Answer: A What is ambiguity in a Context-Free Grammar? A. A situation where a string can be derived by more than one parse tree B. A situation where a string cannot be derived by any parse tree C. A situation where a string has more than one non-terminal symbol D. None of the above Answer: A What is Chomsky normal form for a Context-Free Grammar? A. A form in which all production rules have exactly one non-terminal symbol on the right-hand side B. A form in which all production rules have exactly one terminal symbol on the right-hand side C. A form in which all production rules have exactly two non-terminal symbols on the right-hand side D. None of the above Answer: A What is the purpose of a terminal symbol in a Context-Free Grammar? A. To represent basic elements of the language B. To represent non-terminal symbols C. To specify production rules D. None of the above Answer: A What is a rightmost derivation in a Context-Free Grammar? A. A derivation in which the rightmost non-terminal symbol is always replaced in each step B. A derivation in which the rightmost terminal symbol is always replaced in each step C. A derivation in which the leftmost non-terminal symbol is always replaced in each step D. A derivation in which the leftmost terminal symbol is always replaced in each step Answer: A What is the difference between a leftmost and rightmost derivation in a Context-Free Grammar? A. The order in which the non-terminal symbols are replaced in each step B. The order in which the terminal symbols are replaced in each step C. The type of grammar being used D. None of the above Answer: A


Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. What is a derivation tree in context-free grammars? Answer: A derivation tree shows how a given string can be derived from the start symbol of the grammar. Define sentential form in the context of CFGs. Answer: A sentential form is a string consisting of terminals and nonterminals that can be derived from the start symbol of a CFG. What is the difference between leftmost and rightmost derivations? Answer: A leftmost derivation replaces the leftmost nonterminal in each step, while a rightmost derivation replaces the rightmost nonterminal in each step. What is a parse tree in context-free grammars? Answer: A parse tree is a graphical representation of the derivation of a string in a context-free grammar. What is a production rule in a CFG? Answer: A production rule is a rule that specifies how a nonterminal can be replaced with a sequence of terminals and nonterminals. What is a nullable symbol in a CFG? Answer: A nullable symbol is a nonterminal that can derive the empty string. Define ambiguous grammars. Answer: An ambiguous grammar is a grammar that can derive a string in multiple ways, leading to multiple parse trees. What is the Chomsky normal form of a CFG? Answer: The Chomsky normal form is a form of a CFG where every production rule has either two nonterminals or one terminal on the right-hand side. What is the difference between left recursion and right recursion in a CFG? Answer: Left recursion is when a nonterminal appears as the leftmost symbol in one of its production rules, while right recursion is when it appears as the rightmost symbol. What is the difference between a terminal and a nonterminal symbol in a CFG? Answer: Terminal symbols are symbols that appear in the input string, while nonterminal symbols are symbols that can be replaced by a sequence of terminals and nonterminals during the derivation.

Context-Free Grammar (CFG) is a formalism that is widely used to describe the syntax of programming languages, natural languages, and other formal languages. In order to work with CFGs, it is important to understand some key terminologies. A sentential form is a sequence of terminals and nonterminals that can be derived from the start symbol of a CFG. A derivation is a sequence of sentential forms that show how a string can be derived from the start symbol of a grammar. A derivation tree is a tree structure that shows how a string can be derived from the start symbol of a grammar. A production rule is a rule that specifies how a nonterminal can be replaced with a sequence of terminals and nonterminals. The left-hand side of a production rule is a single nonterminal, while the right-hand side consists of one or more symbols, which can be either terminals or nonterminals. A nullable symbol is a nonterminal that can derive the empty string. A nullable symbol is useful in the construction of the FIRST and FOLLOW sets, which are used to help parse a string according to a CFG. An ambiguous grammar is a grammar that can derive a string in multiple ways, leading to multiple parse trees. Ambiguous grammars can be problematic, as they can lead to different interpretations of the same string. The Chomsky normal form is a form of a CFG where every production rule has either two nonterminals or one terminal on the right-hand side. The Chomsky normal form is useful in many applications, including the analysis of the complexity of parsing algorithms. Left recursion is when a nonterminal appears as the leftmost symbol in one of its production rules, while right recursion is when it appears as the rightmost symbol. Left recursion can be problematic, as it can lead to an infinite loop in some parsing algorithms. Terminal symbols are symbols that appear in the input string, while nonterminal symbols are symbols that can be replaced by a sequence of terminals and nonterminals during the derivation. The start symbol is a special nonterminal symbol that is the initial symbol of the grammar, and is used to derive all valid strings in the language described by the grammar.